<!-- 发现 -->
<template>
	<view class="">
		<u-navbar :is-back="false">
			<view class="flex-bettwen padding-lr20 w100">
				<view class="flex-center">
					<image :src="shopInfo.logoImg" mode="aspectFill" class="logo-item m-r20"></image>
					<text class="fs28" style="font-weight: bold;">{{shopInfo.name}}</text>
				</view>
				<!-- <u-icon name="scan" size="40" color="#999999"></u-icon> -->
			</view>
		</u-navbar>


		<scroll-view scroll-y="true" :style="{'height': scrollViewHeight}" @scrolltolower="handleToLower"
			@refresherrefresh="refresherrefreshEvent" @refresherrestore="refresherrestoreEvent">
			<view class="br-line bg-white  padding20 margin20  br16" @click="goPage('/pages/mallData/mallData')">
				<view class="flex-bettwen">
					<view class="">
						<text style="font-weight: bold;">店铺数据</text>
						<text class="fs26 color-gray m-l20">近7日数据</text>
					</view>
					<view class="fs26 color-gray m-l20">
						<text>更多数据</text>
						<u-icon name="arrow-right" class="m-l20"></u-icon>
					</view>
				</view>

				<view class="flex-bettwen m-t40">
					<view class="center flex1">
						<view class="fs22 color-gray">商品浏览量</view>
						<view class="m-t20" style="font-weight: 500;">209.886</view>
					</view>
					<view class="center flex1">
						<view class="fs22 color-gray">支付转化率</view>
						<view class="m-t20" style="font-weight: 500;">20.98%</view>
					</view>
					<view class="center flex1">
						<view class="fs22 color-gray">成交金额</view>
						<view class="m-t20" style="font-weight: 500;">￥119.232.88</view>
					</view>
					<view class="center flex1">
						<view class="fs22 color-gray">成交订单量</view>
						<view class="m-t20" style="font-weight: 500;">194</view>
					</view>
				</view>
			</view>
			<view class="margin-lr20 m-t30 m-b20 bg-white padding30 flex-bettwen br16"
				@click="goPage('/pages/order/order')">
				<view class="center">
					<view class="" style="font-weight: 500;">6</view>
					<view class="color-gray m-t10 fs26">待支付</view>
				</view>
				<view class="center">
					<view class="" style="font-weight: 500;">6</view>
					<view class="color-gray m-t10 fs26">待发货</view>
				</view>
				<view class="center">
					<view class="" style="font-weight: 500;">30</view>
					<view class="color-gray m-t10 fs26">待收货</view>
				</view>
				<view class="center">
					<view class="" style="font-weight: 500;">14</view>
					<view class="color-gray m-t10 fs26">待评价</view>
				</view>
				<view class="center">
					<view class="" style="font-weight: 500;">3</view>
					<view class="color-gray">退换/售后</view>
				</view>
			</view>
			<view class="swiper-container">
				<swiper class="swiper padding-lr20 h-200" circular :indicator-dots="indicatorDots" :autoplay="false"
					:duration="duration">
					<swiper-item class="flex-bettwen">
						<view class="center scroll-item" @click="goPage(false)">
							<u-icon name="calendar-fill" size="55" color="#1296db"></u-icon>
							<view class="color-gray m-t20 fs26">制单管理</view>
						</view>
						<view class="center scroll-item"
							@click="goPage('/pages/commodityManagement/commodityManagement')">
							<u-icon name="bag-fill" size="55" color="#1296db"></u-icon>
							<view class="color-gray m-t20 fs26">商品管理</view>
						</view>
						<view class="center scroll-item" @click="goPage('/pages/order/order')">
							<u-icon name="file-text-fill" size="55" color="#1296db"></u-icon>
							<view class="color-gray m-t20 fs26">订单管理</view>
						</view>
						<view class="center scroll-item" @click="goPage('/pages/afterSale/afterSale')">
							<u-icon name="car-fill" size="55" color="#1296db"></u-icon>
							<view class="color-gray m-t20 fs26">售后管理</view>
						</view>
						<view class="center scroll-item" @click="goPage('/pages/appraise/appraise')">
							<u-icon name="chat-fill" size="55" color="#1296db"></u-icon>
							<view class="color-gray m-t20 fs26">评价管理</view>
						</view>
					</swiper-item>
					<swiper-item class="flex-bettwen">
						<view class="center scroll-item" @click="goPage(false)">
							<u-icon name="red-packet-fill" size="55" color="#1296db"></u-icon>
							<view class="color-gray m-t20 fs26">优惠券</view>
						</view>
					</swiper-item>
				</swiper>
			</view>
			<view class="padding20 m-t30">
				<view class="flex-bettwen">
					<view class="flex-center">
						<image src="@/static/tab-icon8.png" mode="" class="icon-fire"></image>
						<text style="font-weight: bold;" class="m-l10 fs34">商机中心</text>
						<text class="fs24 color-gray m-l20">积极报价，助力达成成交~</text>
					</view>
					<view class="fs26 color-gray m-l20" @click="goMore">
						<text>更多</text>
						<u-icon name="arrow-right" class="m-l20"></u-icon>
					</view>
				</view>
				<view class="m-t30">
					<u-waterfall ref="waterfall" v-model="flowList">
						<template v-slot:left="{leftList}">
							<view class="waterfall-item-l bg-white hidden br16 m-b20" @click="goDetail(item)"
								v-for="(item, index) in leftList" :key="index">
								<view class="img-box br-top-letfright16 hidden">
									<view class="" @click.stop="closeItem(item)">
										<u-icon name="close-circle-fill" size="40" class="close-icon"></u-icon>
									</view>
									<!-- <u-lazy-load :image="item.enquiryPicture[0]" class="image-item" height="300"></u-lazy-load> -->
									<image :src="item.enquiryPicture[0]" mode="aspectFill" class="goods-image"></image>
								</view>
								<!-- <image src="/static/images/img-goods.jpg" mode="" class="goods-image"></image> -->
								<view class="padding20">
									<view class=" ">
										<view class="text-overflow3 fs26">{{item.remark}}</view>
										<view class="diy-item m-t10" v-if="item.isCustomized">接受定制</view>
										<view class="m-t20 flex-bettwen m-b10">
											<view class="">
												<text class="price-color fs30"
													style="font-weight: bold;">{{item.number}}</text>
												<text class="fs24 color-gray">{{item.unit}}</text>
											</view>
											<view class="flex-center">
												<view class="position-r m-r10" @click.stop="goChat(item)">
													<u-icon name="chat-fill" class="m-r10" color="#10a4db"
														size="36"></u-icon>
													<view class="tags" v-if="item.unReadCount">{{item.unReadCount}}
													</view>
												</view>
												<!-- <u-icon name="chat-fill" class="m-r10" color="#10a4db" size="36"
													@click="goChat(item)"></u-icon> -->
												<u-button size="mini" type="default" :plain="true"
													v-if="item.offer !== '0'" @click="offerPrice(item)">已报价</u-button>
												<u-button size="mini" type="primary" :plain="true" v-else
													@click="offerPrice(item)">报价</u-button>
											</view>
										</view>
									</view>
								</view>

							</view>
						</template>
						<template v-slot:right="{rightList}">
							<view class="waterfall-item-r bg-white m-b20" @click="goDetail(item)"
								v-for="(item, index) in rightList" :key="index">
								<view class="img-box br-top-letfright16 hidden">
									<view class="" @click.stop="closeItem(item)">
										<u-icon name="close-circle-fill" size="40" class="close-icon"></u-icon>
									</view>

									<!-- <u-lazy-load :image="item.enquiryPicture[0]" class="image-item "></u-lazy-load> -->
									<image :src="item.enquiryPicture[0]" mode="aspectFill" class="goods-image"></image>
								</view>
								<!-- <image src="/static/images/img-goods.jpg" mode="" class="goods-image"></image> -->
								<view class="padding20">
									<view class=" ">
										<view class="text-overflow3 fs26">{{item.remark}}</view>
										<view class="diy-item m-t10" v-if="item.isCustomized">接受定制</view>
										<view class="m-t20 flex-bettwen m-b10">
											<view class="">
												<text class="price-color fs30"
													style="font-weight: bold;">{{item.number}}</text>
												<text class="fs24 color-gray">{{item.unit}}</text>
											</view>
											<view class="flex-center">
												<view class="position-r m-r10" @click.stop="goChat(item)">
													<u-icon name="chat-fill" class="m-r10" color="#10a4db"
														size="36"></u-icon>
													<view class="tags" v-if="item.unReadCount">{{item.unReadCount}}
													</view>
												</view>

												<!-- <u-icon name="chat-fill" class="m-r10" color="#10a4db" size="36"
													@click="goChat(item)"></u-icon> -->
												<u-button size="mini" type="default" :plain="true"
													v-if="item.offer !== '0'" @click="offerPrice(item)">已报价</u-button>
												<u-button size="mini" type="primary" :plain="true" v-else
													@click="offerPrice(item)">报价</u-button>
											</view>
										</view>
									</view>
								</view>
							</view>
						</template>
					</u-waterfall>
				</view>


			</view>
		</scroll-view>




		<u-popup v-model="showWin" @close="closeEnquiryWin" mode="bottom" :closeable="true" border-radius="16"
			:safe-area-inset-bottom="true">
			<view class="padding30">
				<!-- 只能有一个根元素 -->
				<view class="sticky center">
					<view class="center fs30 m-b30" style="font-weight: bold;">报价</view>
				</view>

				<view class="m-b20 hidden br12 bg-white flex" v-if="currentInfo.enquiryPicture.length !== 0">
					<view class="w-200 h-200 br16 hidden">
						<u-lazy-load :image="currentInfo.enquiryPicture[0]" img-mode="widthFix"
							class="w-200 h-200"></u-lazy-load>
					</view>
					<view class="flex1 padding-lr20 flex-column-between" style="">
						<view class="text-overflow3 fs26">{{currentInfo.remark}}</view>
						<view class="">
							<view class="diy-item m-t10" v-if="currentInfo.isCustomized">接受定制</view>
						</view>
						<view class="flex-bettwen" :class="currentInfo.isCustomized?'':'m-t40'">
							<view class="">
								<text class="price-color fs30" style="font-weight: bold;">{{currentInfo.number}}</text>
								<text class="fs24 color-gray">{{currentInfo.unit}}</text>
							</view>
						</view>
					</view>
				</view>


				<view class="padding-tb20">
					<view class="flex-center">
						<text class="price-color">*</text>
						<text style="font-weight: bold;">报价信息</text>
						<view class="color-gray fs24">（可选择<text class="blue-color">已有商品</text>报价或<text
								class="color-blue">手动填写</text>报价信息） </view>
					</view>


					<view class="m-t20 flex">
						<!-- <view class="flex-column-center br-line-dashed br12 w-150 h-150 m-r20" @click="chooseImage">
							<view class="center">
								<u-icon name="photo-fill" size="50" color="#999999"></u-icon>
								<view class="fs20 color-gray m-t10">上传图片</view>
							</view>
						</view> -->
						<view class="flex-column-center br-line-dashed br12 w-150 h-150"
							@click="goPage('/pages/selectGoods/selectGoods')">
							<view class="center">
								<u-icon name="bag-fill" size="50" color="#999999"></u-icon>
								<view class="fs20 color-gray m-t10">选择店内商品</view>
							</view>
						</view>
						<view class="m-l20 image-box" v-if="tempFilePathsImg">
							<image :src="tempFilePathsImg" class="w-150 h-150 br12" mode=""></image>
							<u-icon name="minus-circle-fill" class="minus-circle-fill" size="40" @click="delImg"
								color="#d00421"></u-icon>
						</view>

						<view class="m-l20 image-box" v-if="goodsInfo.cover">
							<image :src="goodsInfo.cover" class="w-150 h-150 br12" mode=""></image>
							<u-icon name="minus-circle-fill" class="minus-circle-fill" size="40" @click="delGoods"
								color="#d00421"></u-icon>
						</view>
					</view>

					<view class="flex-bettwen m-t30">
						<text class="price-color">*</text>
						<text>价&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;格</text>
						<view class="flex-bettwen flex1 m-l30">
							<input type="number" placeholder="请填写报价价格" v-model="paramsAddEnquriy.price" class="fs28" />
							<view class="flex-center" @click="showUnit = true">
								<text class="m-r20">元/{{currentText}}</text>
								<u-icon name="arrow-down"></u-icon>
							</view>
						</view>
					</view>

					<view class="flex-bettwen flex-bettwen m-t30">
						<view class="flex-center">
							<text class="price-color">*</text>
							<text>货品类型</text>
						</view>
						<view class="">
							<u-tag text="定做" @click="paramsAddEnquriy.goodsType = '1'"
								:type="paramsAddEnquriy.goodsType == '1'?'success':'info'" class="m-r20" />
							<u-tag text="现货" @click="paramsAddEnquriy.goodsType ='0'"
								:type="paramsAddEnquriy.goodsType == '0'?'success':'info'" />
						</view>
					</view>

					<view class="describe-textarea">
						<view class="flex-center">
							<text class="price-color">*</text>
							<text>报价信息</text>
						</view>
						<textarea class="textarea-box m-t20" :maxlength="-1" v-model="paramsAddEnquriy.details"
							placeholder="请描述主要特征、品名、成份、工艺、用途、规格等"></textarea>
					</view>


					<view class="" style="margin-top: 100rpx;">
						<view class="color-gray" style="font-size: 20rpx;">真诚报价，赢取信任，共同发展；<text
								class="price-color">避免低价诱导</text>，若经查实，则可能面临 <text class="price-color">封禁店铺</text>
						</view>
						<u-button type="primary" class="m-t30" @click="sureAdd">提交报价</u-button>
					</view>
				</view>
			</view>
		</u-popup>

		<!-- 单位弹窗 -->
		<u-popup v-model="showUnit" mode="bottom">
			<view class="center">
				<view class="padding30 " v-for="(item,index) in unitList" :key="index"
					:class="currentUnit == item.value?'color-blue':''" @click="selcetItem(item)">{{item.text}}</view>
				<view class="line-x"></view>
			</view>
		</u-popup>

		<!-- 关闭提示 -->
		<u-modal v-model="showSureClose" @cancel="noShowEvent" @confirm="sureCloseEvent" :content="content"
			mask-close-able show-cancel-button cancel-text='是,不再提示' confirm-text="确认"></u-modal>

		<!-- 提示框 -->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		enquiryList,
		enquiryAdd,
		enquiryOfferList
	} from '@/api/enquriy/index'
	import {
		requestUrl
	} from '@/common/js/config.js'

	let WebIM = require("@/utils/WebIM")["default"];
	let disp = require("@/utils/broadcast");
	import imUtil from '@/utils/imUtil';
	export default {
		data() {
			return {

				unitList: [{
						text: '米',
						value: '0'
					},
					{
						text: '条',
						value: '1'
					},
					{
						text: '码',
						value: '2'
					},
					{
						text: '公斤',
						value: '3'
					},
				],

				tablist: [{
						title: '制单管理',
						url: '',
						icon: 'order'
					},
					{
						title: '商品管理',
						url: '/pages/commodityManagement/commodityManagement',
						icon: 'bag-fill'
					},
					{
						title: '订单管理',
						url: '/pages/order/order',
						icon: 'file-text-fill'
					},
					{
						title: '售后管理',
						url: '',
						icon: 'car-fill'
					},
					{
						title: '评价管理',
						url: '',
						icon: 'chat-fill'
					},
					{
						title: '优惠券',
						url: '',
						icon: 'red-packet-fill'
					},
				],

				flowList: [],
				indicatorDots: true,
				autoplay: true,
				interval: 2000,
				duration: 500,
				params: { // 询价列表参数
					platform: 'sj',
					shopId: '',
					pageNum: 1,
					pageSize: 20,
				},
				showWin: false,
				showUnit: false,
				currentInfo: {
					enquiryPicture: []
				}, // 选择当前报价信息
				currentText: '米',
				currentUnit: '0',
				paramsAddEnquriy: { // 添加报价参数
					enquiryId: '', // 询价单id
					shopId: '', // 商家id
					shopName: '', // 商家名称
					details: '', // 报价详情
					price: '', // 价格
					unit: 0, // 0-米 1-条 2-码 3-公斤 4-本
					picture: '', // 上传图片
					product: '', // 产品id
					goodsType: '0', // 0-现货 1-定做
					imUserName: '', // 环信账号
				},
				tempFilePathsImg: '',
				goodsInfo: {
					cover: ''
				}, // 选择商品信息
				showSureClose: false, // 控制显示关闭提示框
				content: '确定暂时隐藏该报价？', // 提示框文本
				initCloseState: false, // 初始化关闭状态
				currentEnquriyIdx: null,
				statusBar: '',
				scrollViewHeight: '',

				clientImUserName: '', // 客户询价环信账号
				isSend: false,
				shopInfo: {},
				conversationList: []
			}
		},
		onLoad(options) {

		},
		onUnload() {
			uni.$off('selectGoods')
		},
		mounted() {
			// 取屏幕边界到安全区域距离
			let res = uni.getSystemInfoSync()
			let height = 0
			let sysInfo = uni.getSystemInfoSync()
			if (sysInfo.osName == 'ios') {
				height = 47
			} else {
				height = 44
			}

			this.statusBar = res.statusBarHeight + height
			this.scrollViewHeight = `calc(100vh - ${this.statusBar}px)`


			// let imToken = uni.getStorageSync('imToken')
			// let imUserName = uni.getStorageSync('imUserName')
			// imUtil.loginImBytoken(imUserName, imToken)
			this.shopInfo = uni.getStorageSync('shopInfo')


			// 取会话列表
			setTimeout(() => {
				that.getLocalConversationlist();
			}, 100)
			if (!this.shopInfo.id) {
				uni.navigateTo({
					url: '/pages/login/index'
				})
			} else {
				this.params.shopId = this.shopInfo.id

				this.paramsAddEnquriy.imUserName = uni.getStorageSync('imUserName')
				this.paramsAddEnquriy.shopName = this.shopInfo.name
				this.paramsAddEnquriy.shopId = this.shopInfo.id
				this.params.shopId = this.shopInfo.id

				this.getEnquriyList()
			}



			let that = this
			WebIM.conn.addEventHandler("eventName", {
				// 当前用户收到自定义消息。
				onCustomMessage: function(message) {
					console.log('在home下面监听到自定义消息了~~~', message);
					console.log('这是自定义消息的询价id', message.customExts.enquiryId);
					// 取会话列表
					setTimeout(() => {
						that.getLocalConversationlist();
					}, 100)
					that.$refs.waterfall.clear()

					that.getEnquriyList(message.customExts.enquiryId)
				},
			})



			uni.$on('selectGoods', (e) => {
				console.log('拿到商品数据了', e);
				this.goodsInfo = e
				this.paramsAddEnquriy.product = e.id
				if (e.unit == '米') {
					this.paramsAddEnquriy.unit = 0
					this.currentUnit = 0
				} else if (e.unit == '条') {
					this.paramsAddEnquriy.unit = 1
					this.currentUnit = 1
				} else if (e.unit == '码') {
					this.paramsAddEnquriy.unit = 2
					this.currentUnit = 2
				} else if (e.unit == '公斤') {
					this.paramsAddEnquriy.unit = 3
					this.currentUnit = 3
				} else {
					this.paramsAddEnquriy.unit = 4
					this.currentUnit = 4
				}
				this.currentText = e.unit
				this.paramsAddEnquriy.price = e.price
			})

		},

		methods: {
			// 取本地会话列表
			getLocalConversationlist() {
				const myName = uni.getStorageSync("myUsername");
				const me = this;
				uni.getStorageInfo({
					success: function(res) {
						let storageKeys = res.keys;
						let newChatMsgKeys = [];
						let historyChatMsgKeys = [];
						let len = myName.length;
						storageKeys.forEach((item) => {
							if (item.slice(-len) == myName && item.indexOf("rendered_") == -1) {
								newChatMsgKeys.push(item);
							} else if (
								item.slice(-len) == myName &&
								item.indexOf("rendered_") > -1
							) {
								historyChatMsgKeys.push(item);
							} else if (item === "INFORM") {
								newChatMsgKeys.push(item);
							}
						});
						me.packageConversation(newChatMsgKeys, historyChatMsgKeys);
					},
				});
			},
			//组件会话列表方法
			packageConversation(newChatMsgKeys, historyChatMsgKeys) {
				const me = this;
				const myName = uni.getStorageSync("myUsername");
				let conversationList = [];
				let lastChatMsg; //最后一条消息
				for (let i = historyChatMsgKeys.length; i > 0, i--;) {
					let index = newChatMsgKeys.indexOf(historyChatMsgKeys[i].slice(9));
					if (index > -1) {
						let newChatMsgs = uni.getStorageSync(newChatMsgKeys[index]) || [];
						if (newChatMsgs.length) {
							lastChatMsg = newChatMsgs[newChatMsgs.length - 1];
							lastChatMsg.unReadCount = newChatMsgs.length;
							newChatMsgKeys.splice(index, 1);
						} else {
							let historyChatMsgs = uni.getStorageSync(historyChatMsgKeys[i]);
							if (historyChatMsgs.length) {
								lastChatMsg = historyChatMsgs[historyChatMsgs.length - 1];
							}
						}
					} else {
						let historyChatMsgs = uni.getStorageSync(historyChatMsgKeys[i]);
						if (historyChatMsgs.length) {
							lastChatMsg = historyChatMsgs[historyChatMsgs.length - 1];
						}
					}
					if (
						lastChatMsg &&
						(lastChatMsg.chatType == "groupchat" ||
							lastChatMsg.chatType == "chatRoom")
					) {
						lastChatMsg.groupName = me.groupName[lastChatMsg.info.to];
					}
					lastChatMsg && lastChatMsg.username != myName &&
						conversationList.push(lastChatMsg);
				}
				for (let i = newChatMsgKeys.length; i > 0, i--;) {
					let newChatMsgs = uni.getStorageSync(newChatMsgKeys[i]) || [];
					if (newChatMsgs.length) {
						lastChatMsg = newChatMsgs[newChatMsgs.length - 1];
						lastChatMsg.unReadCount = newChatMsgs.length;
						if (
							lastChatMsg.chatType == "groupchat" ||
							lastChatMsg.chatType == "chatRoom"
						) {
							lastChatMsg.groupName = me.groupName[lastChatMsg.info.to];
						}
						lastChatMsg.username != myName && conversationList.push(lastChatMsg);
					}
				}
				conversationList.sort((a, b) => {
					return b.time - a.time;
				});
				this.setData({
					conversationList: conversationList,
				});


				console.log('这是本地会话列表1', conversationList);
			},

			// 更新数据
			updateData() {
				this.getEnquriyList()
			},

			handleToLower() {
				console.log('触底了');
				this.params.pageNum += 1
				this.getEnquriyList()
			},
			refresherrefreshEvent() {

			},
			refresherrestoreEvent() {

			},
			goMore() {
				this.$emit('goMore', 1)
			},
			goDetail(item) {
				uni.navigateTo({
					url: `/pages/opportunity/enquiry-detail?enquiryId=${item.enquiryId}`
				})
			},
			// 单聊
			goChat(detail) {
				console.log('detail~~~~', detail);
				if (detail.imUserName) {
					var my = uni.getStorageSync("myUsername");
					var nameList = {
						myName: my,
						your: detail.imUserName,
						yourNickName: ''
					};

					const friendUserInfoMap = getApp().globalData.friendUserInfoMap;
					if (friendUserInfoMap.has(nameList.your) && friendUserInfoMap.get(nameList.your)?.nickname) {
						nameList.yourNickName = friendUserInfoMap.get(nameList.your).nickname;
					}

					// 取对方用户属性
					WebIM.conn.fetchUserInfoById(detail.imUserName).then((res) => {
						console.log('获取对方属性', res);
						nameList.yourNickName = res.data[detail.imUserName].nickname
						nameList.avatarurl = res.data[detail.imUserName].avatarurl


						// if (detail.offer !== '0') {
						// 	uni.setStorageSync('quoteId', detail.quoteId)
						// } else {
						// }

						uni.setStorageSync('enquiryId', detail.enquiryId)

						uni.navigateTo({
							url: "/pages/chatroom/chatroom?username=" + encodeURIComponent(JSON.stringify(
								nameList)),
						});
					}, (err) => {
						if (err.message == 'appkey or token error') {
							uni.showToast({
								title: '登录已失效，请重新登录',
								icon: 'none'
							})
							uni.navigateTo({
								url: '/pages/login/index'
							})
						}
					});


				} else {
					return uni.showToast({
						title: '当前用户未注册环信信息',
						icon: 'none'
					})
				}


			},


			// // 去聊天
			// goChat(data) {
			// 	if (data.imUserName) {
			// 		uni.navigateTo({
			// 			url: `/pages/msg/messageDetail?data=${data.imUserName}&enquriyInfo=${encodeURIComponent(JSON.stringify(data))}`
			// 		});
			// 	} else {
			// 		return uni.showToast({
			// 			title: '当前用户未注册环信信息',
			// 			icon: 'none'
			// 		})
			// 	}
			// },
			// 不再显示
			noShowEvent() {
				this.initCloseState = true
				this.$refs.waterfall.remove(this.currentEnquriyIdx)
			},
			// 确认关闭
			sureCloseEvent() {
				this.$refs.waterfall.remove(this.currentEnquriyIdx)
			},
			// 上传图片
			uploadFile(url) {
				console.log(requestUrl + '/api/common/upload');
				return new Promise((resolve, reject) => {
					uni.uploadFile({
						url: 'http://8.138.15.166:8080' + '/api/common/upload', //仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						success: (res) => {
							console.log('视频', JSON.parse(res.data).url);
							resolve(JSON.parse(res.data).url)
							// that.params.Video = JSON.parse(res.data).url
						},
						fail: (err) => {
							console.log(err);
						}
					});

				})
			},
			// 删除图片
			delImg() {
				this.tempFilePathsImg = ''
			},
			// 删除商品
			delGoods() {
				this.goodsInfo = {
					cover: ''
				}
				this.paramsAddEnquriy.unit = 0
				this.paramsAddEnquriy.price = ''
				this.paramsAddEnquriy.product = ''
			},
			// 发送消息
			sendMsg() {
				let that = this
				let option = {
					chatType: 'singleChat', // 会话类型，设置为单聊。
					type: 'txt', // 消息类型。
					to: this.fromId, // 消息接收方（用户 ID)。
					msg: '您好，已为您提供报价请查看' // 消息内容。
				}
				let msg = WebIM.message.create(option);
				WebIM.conn.send(msg).then(() => {
					console.log('消息发送成功');
					that.content = ''
				}).catch((e) => {
					console.log("消息发送失败", e);
				})
			},
			// 提交报价
			async sureAdd() {
				if (this.isSend) return
				console.log('提交报价参数', this.paramsAddEnquriy);
				if (!this.paramsAddEnquriy.product && !this.tempFilePathsImg) {
					return this.$refs.uToast.show({
						title: '请上传图片',
						type: 'error',
					})
				}


				if (!this.paramsAddEnquriy.price) {
					return this.$refs.uToast.show({
						title: '请输入价格',
						type: 'error',
					})
				}

				if (!this.paramsAddEnquriy.details) {
					return this.$refs.uToast.show({
						title: '请输入报价信息',
						type: 'error',
					})
				}
				uni.showLoading({
					title: '加载中...',
					icon: 'none'
				})
				this.isSend = true
				if (this.tempFilePathsImg) {
					this.paramsAddEnquriy.picture = await this.uploadFile(this.tempFilePathsImg)
				}
				if (this.paramsAddEnquriy.product) {
					this.paramsAddEnquriy.picture = this.goodsInfo.cover
				}

				// if (this.clientImUserName) {
				// 	this.sendMsg()
				// } else {
				// 	// this.isSend = false
				// 	// uni.hideLoading()
				// 	// return uni.showToast({
				// 	// 	title:'当前用户未注册环信账号'
				// 	// })
				// }


				let res = await enquiryAdd(this.paramsAddEnquriy)
				this.isSend = false
				uni.hideLoading()
				if (res.code == 0) {
					this.$refs.uToast.show({
						title: '报价成功',
						type: 'success',
					})
					// 关闭弹窗
					this.closeEnquiryWin()
				}

			},
			// 隐藏弹窗
			closeEnquiryWin() {
				this.paramsAddEnquriy.unit = 0
				this.paramsAddEnquriy.price = ''
				this.paramsAddEnquriy.product = ''
				this.paramsAddEnquriy.goodsType = '0'
				this.currentText = '米'
				this.currentUnit = '0'
				this.tempFilePathsImg = ''
				this.goodsInfo = {
					cover: ''
				}

				setTimeout(() => {
					this.showWin = false
				}, 1000)
			},

			goPage() {
				uni.navigateTo({
					url: '/pages/selectGoods/selectGoods'
				})
			},
			// 选择单位
			selcetItem(item) {
				this.currentUnit = item.value
				this.currentText = item.text
				this.paramsAddEnquriy.unit = item.value
				this.showUnit = false
			},
			// 上传图片
			chooseImage() {

				if (this.goodsInfo.cover) {
					return this.$refs.uToast.show({
						title: '请删除关联商品',
						type: 'error',
					})
				}
				let that = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function(res) {
						console.log(res.tempFilePaths);
						that.tempFilePathsImg = res.tempFilePaths[0]
					}
				});


			},
			// 暂未开发提示
			showToast() {
				uni.showToast({
					title: '功能暂未开发~'
				})
			},
			// 报价
			offerPrice(item) {
				console.log('点击报价', item);
				this.clientImUserName = item.imUserName
				this.currentInfo = item
				this.paramsAddEnquriy.enquiryId = item.enquiryId
				this.showWin = true
			},
			// 关闭
			closeItem(item) {
				if (!this.initCloseState) {
					this.showSureClose = true
					this.currentEnquriyIdx = item.id
				} else {
					this.$refs.waterfall.remove(item.id)
				}
			},
			// 取询价列表
			async getEnquriyList(enquiryId) {
				let res = await enquiryOfferList(this.params)

				res.rows.map((it) => {
					if (it.enquiryPicture.indexOf('[') !== 0) return
					it.enquiryPicture = JSON.parse(it.enquiryPicture)

					this.conversationList.map((v) => {
						if (it.imUserName == v.info.from) {
							if (v.unReadCount) {
								it.unReadCount = v.unReadCount
							} else {
								it.unReadCount = 0
							}
						}
					})
				})

				this.flowList.push(...res.rows)
			},
			// 登录环信
			loginHuanXin() {
				let imToken = uni.getStorageSync('imToken')
				let imUserName = uni.getStorageSync('imUserName')
				if (imToken && imUserName) {
					imUtil.loginImBytoken(imUserName, imToken)
				}
			},
			getUserInfo() {
				this.$store.dispatch('updateUserInfo')
			},
			goPage(url) {
				if (!url) {
					return uni.showToast({
						title: '敬请期待！',
						icon: 'none'
					})
				}
				if (this.tempFilePathsImg) {
					return this.$refs.uToast.show({
						title: '请先删除图片',
						type: 'error',
					})
				}


				uni.navigateTo({
					url
				})
			}
		},
	}
</script>
<style>

</style>
<style scoped lang="scss">
	.tags {
		width: 25rpx;
		height: 25rpx;
		background: #d8181b;
		border-radius: 50%;
		position: absolute;
		top: -5rpx;
		right: 0rpx;
		color: #fff;
		font-size: 20rpx;
		text-align: center;
		line-height: 25rpx;
	}

	.logo-item {
		width: 50rpx;
		height: 50rpx;
		border-radius: 50%;
	}

	.fw {
		font-weight: bold;
	}

	.icon-fire {
		width: 40rpx;
		height: 50rpx;
	}

	.goods-image {
		width: 100%;
		max-height: 350rpx;
	}

	.image-item {
		width: 100%;
		height: 100rpx;
	}

	.waterfall-item-l {
		width: 348rpx;
		border: 1rpx solid #f2f2f2;
		border-radius: 12rpx 12rpx 12rpx 12rpx;
		overflow: hidden;
	}

	.waterfall-item-r {
		width: 348rpx;
		border: 1rpx solid #f2f2f2;
		margin-left: 20rpx;
		border-radius: 12rpx 12rpx 12rpx 12rpx;
		overflow: hidden;
	}

	.img-box {
		position: relative;

		.close-icon {
			position: absolute;
			top: 10rpx;
			right: 10rpx;
			z-index: 11;
		}
	}

	.diy-item {
		color: #58b261;
		border: 1rpx solid #58b261;
		padding: 5rpx 10rpx;
		display: inline-block;
		border-radius: 12rpx;
		font-size: 20rpx;
	}



	.scroll-item {
		width: 130rpx;
	}

	.image-box {
		position: relative;

		.minus-circle-fill {
			position: absolute;
			top: -10rpx;
			right: -10rpx;
		}
	}

	.describe-textarea {
		border-radius: 16rpx;
		margin-top: 20rpx;
	}

	.textarea-box {
		width: 94%;
		height: 100rpx;
		border-radius: 16rpx;
		background: #f2f2f2;
		font-size: 24rpx;
		// line-height: 40rpx;
		padding: 20rpx;
	}

	/deep/ .uni-swiper-dots {
		position: absolute;
		bottom: 5rpx !important;
	}
</style>
<style>
	page {
		background: #fff;
	}
</style>